import { useState, useCallback } from 'react';

/**
 * Confirm Hook
 * 用于管理确认对话框
 */
export const useConfirm = () => {
  const [confirmState, setConfirmState] = useState(null);

  const showConfirm = useCallback(({
    title = '确认',
    message,
    type = 'info',
    confirmText = '确认',
    cancelText = '取消'
  }) => {
    return new Promise((resolve) => {
      setConfirmState({
        title,
        message,
        type,
        confirmText,
        cancelText,
        onConfirm: () => {
          setConfirmState(null);
          resolve(true);
        },
        onCancel: () => {
          setConfirmState(null);
          resolve(false);
        }
      });
    });
  }, []);

  return {
    confirmState,
    showConfirm
  };
};

